package net.tngou.jtdb.netty;


import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.codec.DelimiterBasedFrameDecoder;
import io.netty.handler.codec.Delimiters;
import io.netty.handler.codec.serialization.ClassResolvers;
import io.netty.handler.codec.serialization.ObjectDecoder;
import io.netty.handler.codec.serialization.ObjectEncoder;
import io.netty.handler.codec.string.StringDecoder;
import io.netty.handler.codec.string.StringEncoder;

/**
* Creates a newly configured {@link ChannelPipeline} for a new channel.
*/
public class ClientInitializer extends ChannelInitializer<SocketChannel> {
//private static final StringDecoder DECODER = new StringDecoder();
//private static final StringEncoder ENCODER = new StringEncoder();
private static final ClientHandler ClIENT_HANDLER = new ClientHandler();


@Override
public void initChannel(SocketChannel ch) throws Exception {
	ChannelPipeline pipeline = ch.pipeline();

//Add the text line codec combination first,
//	pipeline.addLast(new DelimiterBasedFrameDecoder(8192, Delimiters.lineDelimiter()));
////the encoder and decoder are static as these are sharable
//	pipeline.addLast(DECODER);
//	pipeline.addLast(ENCODER);
//and then business logic.
	pipeline.addLast(new ObjectEncoder());
	pipeline.addLast( new ObjectDecoder(ClassResolvers.cacheDisabled(null)));
	pipeline.addLast(ClIENT_HANDLER);
	
	}
}

  
